/*
* Author: Kevin Lam
*/
package com.apps.test;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
public class AjaxTest {
public static final String SERVER_URL = "http://ubc-cc.appspot.com";
public long[] results = new long[10];
public String[] url = new String[10];
//Using hosted web server
@Before
public void prepare() {
url[0] = SERVER_URL+"/auth/ajax/worklist?action=get";
url[1] = SERVER_URL+"/auth/ajax/worklist?action=view&email=btt24@msn.com";
url[2] = SERVER_URL+"/ajax/seats?dept=CPSC&course=410§ion=101";
url[3] = SERVER_URL+"/auth/ajax/worklist?action=get";
url[4] = SERVER_URL+"/auth/ajax/worklist?action=get";
for(int i = 0; i < 3; i++) {
try {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url[i]);
get.setHeader("Cookie", "user=kevin.lam92@gmail.com;auth=e3eeba822df43aaa86abe30bb320b082");
get.addHeader("Accept", "application/xml");
get.addHeader("Content-Type", "application/xml");
HttpResponse responsePost;
responsePost = client.execute(get);
HttpEntity resEntity = responsePost.getEntity();
if (resEntity != null) {
results[i] = resEntity.getContentLength();
System.out.println(results[i]);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Test
public void test() {
for(int i = 0; i< 3 ; i++)
assertTrue(results[i] > 0);
}
}